import { Button } from "antd-mobile";
import { useAppSelector } from "../../store/hook";
import "./index.scss";
import { useDispatch } from "react-redux";
import { logout } from "../../store/features/user";
import { useNavigate } from "react-router-dom";
export interface IMineProps {}

export default function Mine(props: IMineProps) {
  const { user } = useAppSelector((state) => state);
  const dispatch = useDispatch();
  const navigate = useNavigate();
  const handleLogout = () => {
    dispatch(logout()); //清除本地存储、状态机
    navigate("/today");
  };
  return (
    <div>
      <h2 className="user">
        {user.userInfo ? user.userInfo.username : "尚未登录"}
      </h2>
      <Button color="danger" block onClick={handleLogout}>
        退出登录
      </Button>
    </div>
  );
}
